<?php
namespace app\admin\controller;

use think\Controller;
use think\Log;
use think\Db;

class Api extends Controller
{
    public function index()
    {
        return 'admin_api';
    }

    public function login_check()
    {
        if (IS_POST) {
            $username = input('username');
            $password = input('password');

            if (!$username || !$password) {
                return json(['code' => 500, 'msg' => '账号或者密码不能为空']);
            }

            $data = Db::table('vo_admin')->where(['AdminName' => $username, 'Password' => $password])->find();
            if ($data) {
                session('admin_login', ['id' => $data['AdminID'], 'username' => $data['AdminName']]);
                return json(['code' => 200, 'msg' => '登录成功', 'url' => '/admin']);
            } else {
                return json(['code' => 500, 'msg' => '账号或者密码不正确']);
            }
        }
    }
}
